package ma.controller.panels.auxillary;

import ma.model.auxillary.Parameter;

/**
 * The class {@code ParameterSet} is an auxillary class to store
 * parameter informations into an array.
 * @author Oliver Eckstein
 *
 */
public class ParameterSet {
    private String[] parameterInformation;
    private Parameter parameter;
    public static final int OUTPUT_PARAMETER = 0;
    public static final int INPUT_PARAMETER = 1;
    
    /**
     * To create a new {@code ParameterSet}.
     * @param parameter the parameter whose information gets stored into an
     * array.
     * @param parameterType the type of the parameter.
     */
    public ParameterSet(Parameter parameter, int parameterType) {
        this.parameter = parameter;
        if (parameterType == OUTPUT_PARAMETER) {
        	createOutputParameterInformation();	
        } else if (parameterType == INPUT_PARAMETER) {
        	createInputParameterInformation();
        }        
    }
    
    private void createOutputParameterInformation() {
        parameterInformation = new String[4];
    	parameterInformation[0] = parameter.getName();
        parameterInformation[1] = parameter.getGuiAbbreviation();
        parameterInformation[2] = parameter.getUnit();
        Double value;
        if(parameter.getValue() != null) {
            // Round two digits after point
            value = parameter.getValue() * 100;
            value = value.intValue() / 100.0;
        } else {
            value = Double.NaN;
        }        
        parameterInformation[3] = String.valueOf(value);          
    }
    
    private void createInputParameterInformation() {
    	parameterInformation = new String[5];
    	parameterInformation[0] = parameter.getName();
    	parameterInformation[1] = parameter.getAbbreviation();
    	parameterInformation[2] = parameter.getGuiAbbreviation();
    	parameterInformation[3] = parameter.getUnit(); 
        Double paramValue = parameter.getValue();
        if(paramValue == null) {
        	parameterInformation[4] = "";
        } else if (paramValue.equals(Double.NaN)) {
        	parameterInformation[4] = "";    
        } else {
        	parameterInformation[4] = String.valueOf(paramValue);
        }   
    }
    
    /**
     * Returns a {@code String[]} representation of the parameter.
     * @return the {@code String[]} representation of the parameter.
     */
    public String[] getParameterInformation() {
        return parameterInformation;
    }
}
